package com.zy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.bean.bo.chart.ChartRecordsBo;
import com.zy.bean.po.ChartRecords;
import com.zy.bean.qo.ChartSearchQo;
import com.zy.bean.vo.FlowChartVo;
import com.zy.service.ChartRecordsService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 流程图相关的接口
 * @author hanhuafeng
 * @version V1.0
 * @description
 * @date 2023/7/19
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/chart")
public class ChartController {
    private final ChartRecordsService chartRecordsService;

    /**
     * 创建流程图记录,初始化流程图
     *
     * @param chartRecordsBo 流程图记录
     * @return ChartRecords 流程图记录
     */
    @PostMapping("")
    public ChartRecords createChartRecords(@Valid @RequestBody ChartRecordsBo chartRecordsBo) {
        return chartRecordsService.createChartRecords(chartRecordsBo);
    }

    /**
     * 分页获取流程组列表
     *
     * @param chartCode 规则组code
     * @param qo        查询条件
     * @return Page<FlowChartVo> 流程图列表
     */
    @GetMapping("/{chartCode}")
    public Page<FlowChartVo> getChartRecordsByPage(@PathVariable String chartCode,
                                                   ChartSearchQo qo) {
        return chartRecordsService.getChartRecordsByPage(chartCode, qo);
    }


    /**
     * 更新规则组激活状态
     *
     * @param chartCode    流程图code
     * @param activeStatus 激活状态
     */
    @PatchMapping("/{chartCode}/active")
    public void updateChartRecordsActive(@PathVariable String chartCode,
                                         @RequestParam Integer activeStatus) {
        chartRecordsService.updateChartRecordsActive(chartCode, activeStatus);
    }

    /**
     * 更新规则组激活版本号
     *
     * @param chartCode   流程图code
     * @param versionCode 版本号
     */
    @PatchMapping("/{chartCode}/version")
    public void updateChartRecordsActiveVersion(@PathVariable String chartCode,
                                                @RequestParam String versionCode) {
        chartRecordsService.updateChartRecordsActiveVersion(chartCode, versionCode);
    }

    /**
     * 更新流程图记录
     *
     * @param chartCode      流程图code
     * @param chartRecordsBo 流程图记录
     */
    @PatchMapping("/{chartCode}")
    public void updateChartRecords(@PathVariable String chartCode,
                                   @Valid @RequestBody ChartRecordsBo chartRecordsBo) {
        chartRecordsService.updateChartRecords(chartCode, chartRecordsBo);
    }


    /**
     * 根据code删除流程图记录
     *
     * @param chartCode 流程图code
     */
    @DeleteMapping("/{chartCode}")
    public void deleteChartRecords(@PathVariable String chartCode) {
        chartRecordsService.deleteChartRecords(chartCode);
    }
}
